package edu.biwu.request;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;

/**
 * GET或POST请求提交中文
 */
@WebServlet("/req/demo04")
public class RequestDemo04 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //request默认使用的是UTF-8码表
        System.out.println(request.getCharacterEncoding());
        String username = request.getParameter("username");
        System.out.println(username);
        for (byte aByte : username.getBytes()) {//获取"你好"字节
            System.out.println(Integer.toHexString(aByte));//将每个字节转换成16进制
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
